/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-12-15
*/
package com.rzico.article.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.article.entity.BillFare;
import com.rzico.article.service.BillFareService;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.entity.PageResult;
import com.rzico.entity.Pageable;
import com.rzico.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 百道名菜控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-12-15
 */
@Api(description = "百道名菜接口")
@RestController
@RequestMapping("/billFare")
public class BillFareController extends BaseController {

    @Autowired
    private BillFareService billFareService;

    /**
     * 分页查询百道名菜
     *
     * @return
    */
    @ApiOperation("分页查询百道名菜")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "菜名/标题", dataType = "String", paramType = "query") ,
            @ApiImplicitParam(name = "name", value = "菜名", dataType = "String", paramType = "query") ,
            @ApiImplicitParam(name = "content", value = "菜谱简介", dataType = "String", paramType = "query") ,
            @ApiImplicitParam(name = "flavor", value = "口味", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "billFareCategoryId", value = "分类id", dataType = "Integer", paramType = "query")
    })
    public CommResult<BillFare> list(String name,String keyword, String content, String flavor, Integer billFareCategoryId, Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();
        if (StringUtils.isNotEmpty(name)){
            params.put("name", name);
        }
        if (StringUtils.isNotEmpty(keyword)){
            params.put("keyword", keyword);
        }
        if (StringUtils.isNotEmpty(content)){
            params.put("content", content);
        }
        if (StringUtils.isNotEmpty(flavor)){
            params.put("flavor", flavor);
        }
        if (billFareCategoryId != null) {
            params.put("billFareCategoryId", String.valueOf(billFareCategoryId));
        }

        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<BillFare> list = billFareService.selectList(params);
        PageResult<BillFare> pageResult = new PageResult<BillFare>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }

    /**
     * 查询单条百道名菜
     *
     * @return
    */
    @ApiOperation("查询单条百道名菜")
    @GetMapping("/find/{id}")
    public CommResult<BillFare> find(@PathVariable String id) {
        BillFare result = billFareService.findById(id);

        Map<String,Object> data = new HashMap<>();
        data.put("billFare",result);
        return CommResult.success(data);

    }


}
